<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生管理系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', sans-serif;
        }

        body {
            display: flex;
            min-height: 100vh;
            background-color: #f5f5f5;
        }

        .sidebar {
            width: 220px;
            background: linear-gradient(135deg, #1e5799 0%, #207cca 51%, #2989d8 100%);
            color: white;
            height: 100vh;
            position: fixed;
            box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
            transition: all 0.3s;
        }

        .logo {
            padding: 20px;
            text-align: center;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .logo h2 {
            font-size: 18px;
            margin-top: 10px;
        }

        .menu {
            padding: 20px 0;
        }

        .menu-title {
            padding: 10px 20px;
            font-size: 12px;
            color: rgba(255, 255, 255, 0.7);
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        .menu-item {
            padding: 12px 20px;
            display: flex;
            align-items: center;
            color: white;
            text-decoration: none;
            transition: all 0.3s;
            border-left: 3px solid transparent;
        }

        .menu-item:hover {
            background-color: rgba(255, 255, 255, 0.1);
            border-left: 3px solid #fff;
        }

        .menu-item i {
            margin-right: 10px;
            font-size: 16px;
        }

        .menu-item.active {
            background-color: rgba(255, 255, 255, 0.2);
            border-left: 3px solid #fff;
        }

        .main-content {
            flex: 1;
            margin-left: 220px;
            padding: 20px;
            background-color: #fff;
            min-height: 100vh;
        }

        /* 图标使用Unicode字符代替字体图标 */
        .icon {
            font-style: normal;
            display: inline-block;
            width: 20px;
            text-align: center;
        }

        /* 新增统计卡片样式 */

        .sidebar-menu .nav-link {
            color: rgba(255, 255, 255, 0.8);
            padding: 10px 20px;
            margin: 5px 0;
            border-radius: 0;
            transition: all 0.3s;
        }

        .sidebar-menu .nav-link:hover,
        .sidebar-menu .nav-link.active {
            color: white;
            background-color: rgba(255, 255, 255, 0.1);
        }

        .sidebar-menu .nav-link i {
            margin-right: 10px;
            font-size: 1.1rem;
        }

        .card {
            border: none;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s;
            margin-bottom: 20px;
        }

        .card:hover {
            transform: translateY(-5px);
        }

        .stat-card {
            text-align: center;
            padding: 20px;
        }

        .stat-card .icon {
            font-size: 2.5rem;
            margin-bottom: 15px;
        }

        .stat-card .count {
            font-size: 2rem;
            font-weight: bold;
            margin-bottom: 5px;
        }

        .stat-card .label {
            color: #6c757d;
            font-size: 0.9rem;
        }

        /* 为每个卡片设置不同的背景颜色和图标颜色 */
        .stat-card.student-card {
            background-color: #e7f3ff;
        }

        .stat-card.student-card .icon {
            color: #2196f3;
        }

        .stat-card.course-card {
            background-color: #fff3e0;
        }

        .stat-card.course-card .icon {
            color: #ff9800;
        }

        .stat-card.teacher-card {
            background-color: #e8f5e9;
        }

        .stat-card.teacher-card .icon {
            color: #4caf50;
        }
    </style>
</head>

<body>
<!-- 左侧菜单栏 -->
<div class="sidebar">
    <div class="logo">
        <div style="font-size: 24px;">🎓</div>
        <h2>学生管理系统</h2>
    </div>
    <div class="menu">
        <div class="menu-title">主菜单</div>
        <a href="index.html" class="menu-item active">
            <span class="icon">🏠</span> 系统首页
        </a>
        <div class="menu-title">用户管理</div>
        <a href="denglu.html" class="menu-item">
            <span class="icon">🔑</span> 用户登录
        </a>
        <a href="zhuce.html" class="menu-item">
            <span class="icon">✏️</span> 用户注册
        </a>
        <a href="sysuser.html" class="menu-item">
            <span class="icon">👥</span> 系统用户
        </a>
        <div class="menu-title">权限管理</div>
        <a href="sysrole.html" class="menu-item">
            <span class="icon">🛡️</span> 系统角色
        </a>
        <a href="role_list.html" class="menu-item">
            <span class="icon">📋</span> 角色列表
        </a>
        <a href="sysuserrole.html" class="menu-item">
            <span class="icon">🔗</span> 用户角色
        </a>
        <a href="sysmenu.html" class="menu-item">
            <span class="icon">🍔</span> 系统菜单
        </a>
        <a href="sysrolemenu.html" class="menu-item">
            <span class="icon">📊</span> 角色菜单
        </a>
        <div class="menu-title">教学管理</div>
        <a href="student.html" class="menu-item">
            <span class="icon">👨‍🎓</span> 学生管理
        </a>
        <a href="teacher.html" class="menu-item">
            <span class="icon">👩‍🏫</span> 教师管理
        </a>
        <a href="course.html" class="menu-item">
            <span class="icon">📚</span> 课程管理
        </a>
        <a href="studentcourse.html" class="menu-item">
            <span class="icon">📝</span> 学生选课
        </a>
    </div>
</div>
<!-- 主内容区 -->
<div class="main-content">
    <h1>欢迎使用学生管理系统</h1>


    <!-- 统计卡片 -->
    <div class="row">
        <div class="col-md-4">
            <div class="card stat-card student-card">
                <div class="icon"><i class="bi bi-people"></i></div>
                <div class="count" id="totalStudents">0</div>
                <div class="label">学生人数</div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card stat-card course-card">
                <div class="icon"><i class="bi bi-book"></i></div>
                <div class="count" id="totalCourses">0</div>
                <div class="label">课程总数</div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card stat-card teacher-card">
                <div class="icon"><i class="bi bi-person-video2"></i></div>
                <div class="count" id="totalTeachers">0</div>
                <div class="label">教师人数</div>
            </div>
        </div>
    </div>




    <center>
        <h1>请从左侧菜单选择功能模块</h1>
    </center>
</div>
<!-- 只替换原来的script部分即可，其余HTML和CSS保持不变 -->
<script>
    document.addEventListener('DOMContentLoaded', function () {
        // 显示加载状态
        document.getElementById('totalStudents').textContent = '加载中...';
        document.getElementById('totalCourses').textContent = '加载中...';
        document.getElementById('totalTeachers').textContent = '加载中...';

        fetchStatistics();

        // 获取统计数据
        function fetchStatistics() {
            // 检查是否有token
            const token = localStorage.getItem('authToken');
            const headers = {
                'Content-Type': 'application/json'
            };

            if (token) {
                headers['Authorization'] = 'Bearer ' + token;
            }

            // 并行获取所有统计数据
            Promise.all([
                fetch('/api/students/count', { method: 'GET', headers }).then(handleResponse),
                fetch('/api/courses/count', { method: 'GET', headers }).then(handleResponse),
                fetch('/api/teachers/count', { method: 'GET', headers }).then(handleResponse)
            ])
                .then(([students, courses, teachers]) => {
                    updateCount('totalStudents', students);
                    updateCount('totalCourses', courses);
                    updateCount('totalTeachers', teachers);
                })
                .catch(error => {
                    console.error('获取统计数据失败:', error);
                    useMockData();
                });
        }

        function handleResponse(response) {
            if (!response.ok) {
                throw new Error(`HTTP error! status: ${response.status}`);
            }
            return response.json();
        }

        function updateCount(elementId, data) {
            const element = document.getElementById(elementId);
            if (data && data.success) {
                element.textContent = data.data.count;
                element.style.color = ''; // 重置颜色
            } else {
                element.textContent = 'N/A';
                element.style.color = 'red';
                console.error(`获取${elementId.replace('total', '')}数量失败:`, data?.message);
            }
        }

        // 使用模拟数据
        function useMockData() {
            console.log('使用模拟数据');
            document.getElementById('totalStudents').textContent = '0';
            document.getElementById('totalCourses').textContent = '0';
            document.getElementById('totalTeachers').textContent = '0';
        }
    });
</script>
</body>

</html>